package br.unifor.cct.mia.ga.util;

import java.io.Serializable;


public class FeatureConstructionGene implements Serializable {

	private String attribute;
	private String value;
	private String operator;
	private byte activeBit = 1;
	private int attPosition = 0;
	
	public String toString() {
		return attribute+operator+value+"["+activeBit+"]";
	}
	
	public int getAttPosition() {
		return attPosition;
	}
	public void setAttPosition(int attPosition) {
		this.attPosition = attPosition;
	}
	public byte getActiveBit() {
		return activeBit;
	}
	public void setActiveBit(byte activeBit) {
		this.activeBit = activeBit;
	}
	public String getAttribute() {
		return attribute;
	}
	public void setAttribute(String attribute) {
		this.attribute = attribute;
	}
	public String getOperator() {
		return operator;
	}
	public void setOperator(String operator) {
		this.operator = operator;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	
	public Object clone() {
		FeatureConstructionGene clone = new FeatureConstructionGene();
		clone.setActiveBit(this.getActiveBit());
		clone.setAttPosition(this.getAttPosition());
		clone.setAttribute(this.getAttribute());
		clone.setValue(this.getValue());
		clone.setOperator(this.operator);
		return clone;
	}
	
	public boolean equals(Object obj) {
		if ( obj instanceof FeatureConstructionGene ) {
			FeatureConstructionGene param = (FeatureConstructionGene)obj;
			if ( this.attribute.equalsIgnoreCase(param.getAttribute()) 
					&& this.operator.equalsIgnoreCase(param.getOperator())
					&& this.value.equalsIgnoreCase(param.getValue()) )
			{
				return true;
			}
			else {
				return false;
			}			
		}
		else {
			return false;
		}		
	}
	
	public int hashCode() {
		return attPosition*17+
			activeBit*13+
			attribute.hashCode()*7+
			value.hashCode()*11 +
			FeatureConstructionOperators.getHash( FeatureConstructionOperators.getValue(this.operator) )*13;
	}
}
